#include "SysConfig.h"
#include <osgEarth/Config>
#include <osgEarth/StringUtils>
#include <osgDB/fstream>


SysConfig::SysConfig()
{
    this->server_ip = "";
    this->server_port = "";
    this->test = true;
    this->server = "http://127.0.0.1:15000/";
    this->output_url = "";
    stereo_scale = 1.0;

    osgEarth::Config doc;
    std::ifstream in("../user_data/config/sys.xml");

    if(!doc.fromXML(in)){
        return;
    }
    const osgEarth::Config* cfg = doc.child_ptr("config");
    if(!cfg) return;

    const osgEarth::Config* cit = 0;

	//std::string url_search;
	//std::string url_port;
	//std::string url_iploc;
	//std::string url_smt;
	//std::string url_optical;
	//std::string url_landmark;
	//std::string url_iptrack;
	//std::string url_vissent;
	//std::string url_visattack;
	//std::string url_vistopo;
	//std::string url_index;
    cit = cfg->child_ptr("url_search");
    if (cit){this->url_search =(cit->value());}

    cit = cfg->child_ptr("url_port");
    if (cit){this->url_port = cit->value();}

	cit = cfg->child_ptr("url_iploc");
	if (cit) { this->url_iploc = cit->value(); }

	cit = cfg->child_ptr("url_smt");
	if (cit) { this->url_smt = cit->value(); }

	cit = cfg->child_ptr("url_optical");
	if (cit) { this->url_optical = cit->value(); }

	cit = cfg->child_ptr("url_landmark");
	if (cit) { this->url_landmark = cit->value(); }

	cit = cfg->child_ptr("url_iptrack");
	if (cit) { this->url_iptrack = cit->value(); }

	cit = cfg->child_ptr("url_vissent");
	if (cit) { this->url_vissent = cit->value(); }

	cit = cfg->child_ptr("url_visattack");
	if (cit) { this->url_visattack = cit->value(); }

	cit = cfg->child_ptr("url_vistopo");
	if (cit) { this->url_vistopo = cit->value(); }

	cit = cfg->child_ptr("url_index");
	if (cit) { this->url_index = cit->value(); }

	cit = cfg->child_ptr("url_social");
	if (cit) { this->url_social = cit->value(); }

	cit = cfg->child_ptr("url_CyberThreatWidgetList");
	if (cit) { this->url_CyberThreatWidgetList = cit->value(); }

	cit = cfg->child_ptr("url_CyberThreatWidgetChart");
	if (cit) { this->url_CyberThreatWidgetChart = cit->value(); }
}

SysConfig *SysConfig::intance()
{
    static SysConfig sc;
    return &sc;
}

